package com.yikaiye.android.yikaiye.ui.activity.home.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.di.retrofit.BaseModel;
import com.yikaiye.android.yikaiye.di.retrofit.BaseNetCallback;
import com.yikaiye.android.yikaiye.model.ProductDetailDataModel;

public class ProductDetailsViewModel extends BaseViewModel {

    public MutableLiveData<ProductDetailDataModel> productDetailDataModelMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<String> productDetailErrorMutableLiveData = new MutableLiveData<>();

    /**
     * 产品详情
     */
    public void getProductDetails(String id) {
        addSubscribe(mRetrofitHelper.getProductDetails(id).subscribeWith(new BaseNetCallback<ProductDetailDataModel>() {

            @Override
            public void onSuccess(BaseModel<ProductDetailDataModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    productDetailDataModelMutableLiveData.setValue(baseModel.getData());
                } else {
                    productDetailErrorMutableLiveData.setValue(baseModel.getMsg());
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                productDetailErrorMutableLiveData.setValue(message);
            }
        }));
    }

}
